<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="危险源名称" prop="hazardName">
        <el-input
          v-model="queryParams.hazardName"
          placeholder="请输入危险源名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['risk:source:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['risk:source:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['risk:source:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-check"
          size="mini"
          :disabled="multiple"
          @click="handleCheck"
          v-hasPermi="['risk:source:edit']"
        >风险确认</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--		  :loading="exportLoading"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['risk:source:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="sourceList" @selection-change="handleSelectionChange" @row-dblclick="handleRowDblclick">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" width="50" align="center">
        <template slot-scope="scope">
          <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="主键ID" align="center" prop="id" />-->
      <el-table-column label="危险源名称" align="center" >

      <template slot-scope="scope">
        {{ scope.row.hazardName }}
        <el-button
          size="mini"
          type="text"
          icon="el-icon-plus"
          @click="handleControlAdd(scope.row)"
        >新增</el-button>
      </template>
      </el-table-column>
      <el-table-column label="识别日期" align="center" prop="remarkSpare" />
      <el-table-column label="确认日期" align="center" prop="remarkSpare1" />
      <el-table-column label="修订日期" align="center" prop="remarkSpare2" />
      <el-table-column label="修订部门" align="center" prop="deptName" />
      <el-table-column label="修订人员" align="center" prop="createBy" />
<!--      <el-table-column label="备注" align="center" prop="remark" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['risk:source:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['risk:source:remove']"
          >删除</el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-check"-->
<!--            @click="handleCheck(scope.row)"-->
<!--            v-hasPermi="['risk:source:edit']"-->
<!--          >风险确认</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改危险源管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row :gutter="20">
          <el-col :span="12" :xs="24">
        <el-form-item label="危险源名称" prop="hazardName">
          <el-input v-model="form.hazardName" placeholder="请输入危险源名称" />
        </el-form-item>
          </el-col>
          <el-col :span="12" :xs="24">
        <el-form-item label="识别日期" prop="remarkSpare">
          <el-date-picker clearable size="small"
                          v-model="form.remarkSpare"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择识别日期" style="width: 100%">
          </el-date-picker>
          <!--          <el-input v-model="form.remarkSpare" placeholder="请输入备用" />-->
        </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12" :xs="24">
        <el-form-item label="确认日期" prop="remarkSpare1">
          <el-date-picker clearable size="small"
                          v-model="form.remarkSpare1"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择确认日期" style="width: 100%">
          </el-date-picker>
<!--          <el-input v-model="form.remarkSpare1" placeholder="请输入备用1" />-->
        </el-form-item>
          </el-col>
          <el-col :span="12" :xs="24">
        <el-form-item label="修订日期" prop="remarkSpare2">
          <el-date-picker clearable size="small"
                          v-model="form.remarkSpare2"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择修订日期" style="width: 100%">
          </el-date-picker>
<!--          <el-input v-model="form.remarkSpare2" placeholder="请输入备用2" />-->
        </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12" :xs="24">
        <el-form-item label="修订部门" prop="deptId">
          <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择修订部门" style="width: 100%"/>
        </el-form-item>
          </el-col>
          <el-col :span="12" :xs="24">
        <el-form-item label="修订人员" prop="createBy">
          <el-select  v-model="form.createBy" filterable placeholder="选择整改责任人" style="width: 100%">
            <el-option
              v-for="user in filteredUsers"
              :key="user.userId+''"
              :label="user.nickName "
              :value="user.userId+''">
            </el-option>
          </el-select>
        </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" type="textarea"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="controlTitle" :visible.sync="controlOpen" width="800px" append-to-body>
      <el-form ref="controlForm" :model="controlForm" :rules="controlRules" label-width="160px">
        <el-row :gutter="20">
          <el-col :span="12" :xs="24">
            <el-form-item label="危险源" prop="sourceId">
              <el-select v-model="controlForm.sourceId" placeholder="请选择危险源" style="width: 100%">
                <el-option
                  v-for="dict in sourceIdOptions"
                  :key="dict.id"
                  :label="dict.hazardName"
                  :value="dict.id"
                ></el-option>
              </el-select>
              <!--          <el-input v-model="form.sourceId" placeholder="请输入危险源ID" />-->
            </el-form-item>
          </el-col>
          <el-col :span="12" :xs="24">
            <el-form-item label="修订时间" prop="revisionTime">
              <el-date-picker clearable size="small"
                              v-model="controlForm.revisionTime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择修订时间" style="width: 100%">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="作业项目" prop="operatingItem">
          <el-input v-model="controlForm.operatingItem" placeholder="请输入作业项目" />
        </el-form-item>
        <el-form-item label="风险因素" prop="riskFactor">
          <el-input v-model="controlForm.riskFactor" placeholder="请输入风险因素" />
        </el-form-item>
        <el-row :gutter="20">
          <el-col :span="12" :xs="24">
            <el-form-item label="输入类型种类" prop="inputType">
              <el-select v-model="controlForm.inputType" placeholder="请选择输入类型种类" style="width: 100%">
                <el-option
                  v-for="dict in inputTypeOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" :xs="24">
            <el-form-item label="可能造成的危害种类" prop="hazardsTypes">
              <el-select v-model="controlForm.hazardsTypes" multiple placeholder="请选择可能造成的危害种类" style="width: 100%">
                <el-option
                  v-for="dict in hazardsTypeOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="控制措施" prop="protectiveMeasures">
          <el-input v-model="controlForm.protectiveMeasures" type="textarea" placeholder="请输入控制措施" />
        </el-form-item>
        <el-row :gutter="20">
          <el-col :span="12" :xs="24">
            <el-form-item label="事故的可能性(L)" prop="l">
              <el-select v-model="controlForm.l" placeholder="请选择" @change="handleSelectChangeL" style="width: 100%">
                <el-option
                  v-for="dict in lOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel + '('  +dict.dictValue+ ')'"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
              <div style="margin-top: 5px;">
                <el-link style="font-size: 10px ; color: red" target="_blank" @click="showHelp">查看帮助文档</el-link>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="12" :xs="24">
            <el-form-item label="暴露在危险的程度(E)" prop="e">
              <el-select v-model="controlForm.e" placeholder="请选择" @change="handleSelectChangeE" style="width: 100%">
                <el-option
                  v-for="dict in eOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel + '('  +dict.dictValue+ ')'"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12" :xs="24">
            <el-form-item label="发生事故的后果(C)" prop="c">
              <el-select v-model="controlForm.c" placeholder="请选择" @change="handleSelectChangeC" style="width: 100%">
                <el-option
                  v-for="dict in cOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel + '('  +dict.dictValue+ ')'"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" :xs="24">
            <el-form-item label="危险性(D)" prop="d">
              <el-input v-model="controlForm.d" placeholder="请输入D" disabled/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12" :xs="24">
            <el-form-item label="等级" prop="grade">
              <el-input v-model="controlForm.grade" placeholder="请输入等级" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="12" :xs="24">
            <el-form-item label="责任主体" prop="responsibleParty">
              <el-input v-model="controlForm.responsibleParty" placeholder="请输入责任主体" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="位置" prop="position">
          <el-input v-model="controlForm.position" placeholder="请输入位置" type="textarea"/>
        </el-form-item>
        <el-form-item label="避免措施或控制措施" prop="measures">
          <el-input v-model="controlForm.measures" type="textarea" placeholder="请输入避免失控措施或失控后缓解（控制）措施" />
        </el-form-item>
        <!--        <el-form-item label="备注" prop="remark">-->
        <!--          <el-input v-model="controlForm.remark" placeholder="请输入备注" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="备用" prop="remarkSpare">-->
        <!--          <el-input v-model="controlForm.remarkSpare" placeholder="请输入备用" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="备用1" prop="remarkSpare1">-->
        <!--          <el-input v-model="controlForm.remarkSpare1" placeholder="请输入备用1" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="备用2" prop="remarkSpare2">-->
        <!--          <el-input v-model="controlForm.remarkSpare2" placeholder="请输入备用2" />-->
        <!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitControlForm">确 定</el-button>
        <el-button @click="cancelControl">取 消</el-button>
        <!--        <el-button @click="showHelp">查看帮助文档</el-button>-->
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSource, getSource, delSource, addSource, updateSource, exportSource, checkSource, overtimeSource } from "@/api/risk/source";
import { listUserNoPage } from '@/api/system/user'
import Treeselect from '@riophae/vue-treeselect'
import { treeselect } from "@/api/system/dept";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { getCurrentUser } from "@/api/system/user";
import { optionselect, addControl } from "@/api/risk/control";



export default {
  name: "Source",
  components: { Treeselect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 危险源管理表格数据
      sourceList: [],
      // 弹出层标题
      title: "",
      controlTitle: "",
      // 部门树选项
      deptOptions: undefined,
      filteredUsers:[],
      // 是否显示弹出层
      open: false,
      // 危险源ID字典
      sourceIdOptions: [],
      // 输入类型种类字典
      inputTypeOptions: [],
      // 可能造成的危害种类字典
      hazardsTypeOptions: [],
      // L字典
      lOptions: [],
      // E字典
      eOptions: [],
      // C字典
      cOptions: [],
      // D字典
      dOptions: [],
      // 等级字典
      gradeOptions: [],
      controlOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        hazardName: null,
      },
      createBy: "",
      deptId: "",
      lValue: "",
      eValue: "",
      cValue: "",
      showHelpModal: false,
      helpDocumentUrl: process.env.BASE_URL + 'LEC评分规则及对应风险管控层级.pdf',
      // 表单参数
      form: {},
      // 表单参数
      controlForm: {},
      // 表单校验
      rules: {
        hazardName: [
          { required: true, message: "危险源不能为空", trigger: "blur" }
        ],
      },
      controlRules: {
        sourceId: [
          { required: true, message: "危险源不能为空", trigger: "blur" }
        ],
        revisionTime: [
          { required: true, message: "修订时间不能为空", trigger: "blur" }
        ],
        operatingItem: [
          { required: true, message: "作业项目不能为空", trigger: "blur" }
        ],
        riskFactor: [
          { required: true, message: "风险因素不能为空", trigger: "blur" }
        ],
        inputType: [
          { required: true, message: "输入类型种类不能为空", trigger: "blur" }
        ],
        hazardsTypes: [
          { required: true, message: "可能造成的危害种类不能为空", trigger: "blur" }
        ],
        protectiveMeasures: [
          { required: true, message: "控制措施不能为空", trigger: "blur" }
        ],
        l: [
          { required: true, message: "事故发生的可能性(L)不能为空", trigger: "blur" }
        ],
        e: [
          { required: true, message: "人员暴露于危险环境中的频繁程度(E)不能为空", trigger: "blur" }
        ],
        c: [
          { required: true, message: "一旦发生事故可能造成的后果(C)不能为空", trigger: "blur" }
        ],
        position: [
          { required: true, message: "位置不能为空", trigger: "blur" }
        ],
        responsibleParty: [
          { required: true, message: "责任主体不能为空", trigger: "blur" }
        ],
        measures: [
          { required: true, message: "避免失控措施或失控后缓解（控制）措施不能为空", trigger: "blur" }
        ],
      },
    };
  },
  created() {
    this.getCurrentUser();
    console.log(this.createBy)
    this.getTreeselect();
    this.fetchUsers();
    this.getList();
    this.getSources();
    this.getDicts("risk_input_type").then(response => {
      this.inputTypeOptions = response.data;
    });
    this.getDicts("risk_hazards_type").then(response => {
      this.hazardsTypeOptions = response.data;
    });
    this.getDicts("risk_likelihood").then(response => {
      this.lOptions = response.data;
    });
    this.getDicts("risk_exposure").then(response => {
      this.eOptions = response.data;
    });
    this.getDicts("risk_consequence").then(response => {
      this.cOptions = response.data;
    });
    this.getDicts("risk_danger").then(response => {
      this.gradeOptions = response.data;
    });
  },
  methods: {
    /** 查询危险源管理列表 */
    getList() {
      this.loading = true;
      listSource(this.queryParams).then(response => {
        this.sourceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      this.overtime();
    },
    overtime() {
      overtimeSource().then(response => {
        if (response.code === 200) {

        } else {
          this.msgError(response.msg);
        }
      })
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
        // console.log('this.deptOptions:' + JSON.stringify(this.deptOptions))
      });
    },
    getCurrentUser() {
      let currentUser = this.$store.state.user;
      getCurrentUser(currentUser.userId).then(response => {
        this.createBy = response.data.userId
        this.deptId = response.data.deptId
      });
    },
    getSources() {
      optionselect().then(response => {
        this.sourceIdOptions = response.data;
      });
    },
    fetchUsers() {
      this.loading=true;
      listUserNoPage().then(response => {
          this.filteredUsers = response.rows;
          this.loading = false;
        }
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancelControl() {
      this.controlOpen = false;
      this.resetControl();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        hazardName: null,
        remark: null,
        remarkSpare: null,
        remarkSpare1: null,
        remarkSpare2: null,
        createBy: null,
        createTime: null,
        deptId: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.form.createBy = this.createBy+'';
      this.form.deptId = this.deptId;
      const currentDate = new Date()
      const year = currentDate.getFullYear();
      const month = currentDate.getMonth() + 1;
      const day = currentDate.getDate();
      const time = `${year.toString()}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')}`
      this.form.remarkSpare = time;
      this.form.remarkSpare1 = time;
      this.form.remarkSpare2 = time;
      this.open = true;
      this.title = "添加危险源管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSource(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改危险源管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateSource(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSource(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除选中的风险项目及相关风险分级管控数据?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delSource(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    handleCheck(row) {
      const ids = this.ids;
      // const hazardName = row.hazardName;
      this.$confirm('是否确认勾选的危险源?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return checkSource(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("确定成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有危险源管理数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportSource(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    },
    /** 新增按钮操作 */
    handleControlAdd(row) {
      this.getSources();
      this.resetControl();
      this.controlForm.sourceId = row.id;
      this.controlForm.revisionTime = new Date();
      this.lValue = "";
      this.eValue = "";
      this.cValue = "";
      this.controlOpen = true;
      this.controlTitle = "添加风险、危险源识别评分及控制";
    },
    // 表单重置
    resetControl() {
      this.controlForm = {
        id: null,
        sourceId: null,
        revisionTime: null,
        operatingItem: null,
        riskFactor: null,
        inputType: null,
        hazardsType: null,
        protectiveMeasures: null,
        l: null,
        e: null,
        c: null,
        d: null,
        grade: null,
        position: null,
        responsibleParty: null,
        measures: null,
        remark: null,
        remarkSpare: null,
        remarkSpare1: null,
        remarkSpare2: null,
        createBy: null,
        createTime: null,
        deptId: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("controlForm");
    },
    handleSelectChangeL(value) {
      this.lValue = value;
      this.eValue = this.controlForm.e;
      this.cValue = this.controlForm.c;
      console.log('选中的值:', value);
      this.calculationLEC();
    },
    handleSelectChangeE(value) {
      this.eValue = value;
      this.lValue = this.controlForm.l;
      this.cValue = this.controlForm.c;
      console.log('选中的值:', value);
      this.calculationLEC();
    },
    handleSelectChangeC(value) {
      this.cValue = value;
      this.eValue = this.controlForm.e;
      this.lValue = this.controlForm.l;
      console.log('选中的值:', value);
      this.calculationLEC();
    },
    calculationLEC(){
      if (this.lValue !== null && this.eValue !== null && this.cValue !== null && this.lValue !== "" && this.eValue !== "" && this.cValue !== "" ){
        let floatL = parseFloat(this.lValue);
        let floatE = parseFloat(this.eValue);
        let floatC = parseFloat(this.cValue);
        let d = floatL * floatE * floatC;
        this.controlForm.d = d.toFixed(2);
        // 遍历字典，找到第一个满足条件的等级
        console.log(d)
        for (let i = 0; i < this.gradeOptions.length; i ++) {
          const bounds = this.gradeOptions[i].dictValue.split('-').map(Number);
          if (bounds.length>1){
            if (this.controlForm.d >= bounds[0] && this.controlForm.d < bounds[1]) {
              this.controlForm.grade = this.gradeOptions[i].dictLabel;
            }
          }else {
            if (this.controlForm.d >= bounds[0]){
              this.controlForm.grade = this.gradeOptions[i].dictLabel;
            }
          }
        }
      }
    },
    showHelp() {
      // this.showHelpModal = true;
      const helpDocPath = process.env.BASE_URL + 'LEC评分规则及对应风险管控层级.pdf';
      window.open(helpDocPath, '_blank');
    },
    submitControlForm() {
      this.$refs["controlForm"].validate(valid => {
        if (valid) {
          // if (this.form.id != null) {
          //   updateControl(this.form).then(response => {
          //     this.msgSuccess("修改成功");
          //     this.open = false;
          //     this.getList();
          //   });
          // } else {
            addControl(this.controlForm).then(response => {
              this.msgSuccess("新增成功");
              this.controlOpen = false;
              this.getList();
            });
          // }
        }
      });
    },
    handleRowDblclick(row, event, column) {
      // 双击行时的处理逻辑
      console.log('双击行:', row);
      this.$router.push({
        name: 'Control',
        params: { id: row.id }
      });
    }
  }
};
</script>
